using System;
using System.Globalization;
using ns16;
using ns17;
using ns20;

namespace Newtonsoft.Json.Converters
{
	public class EntityKeyMemberConverter : JsonConverter
	{
		private const string string_0 = "System.Data.EntityKeyMember";

		public override void WriteJson(JsonWriter writer, object value, JsonSerializer serializer)
		{
			Interface9 @interface = Class164.smethod_5<Interface9>(value);
			Type type = ((@interface.Object_0 != null) ? @interface.Object_0.GetType() : null);
			writer.WriteStartObject();
			writer.WritePropertyName("Key");
			writer.WriteValue(@interface.String_0);
			writer.WritePropertyName("Type");
			writer.WriteValue((type != null) ? type.FullName : null);
			writer.WritePropertyName("Value");
			if (type != null)
			{
				if (Class138.smethod_0(@interface.Object_0, type, out var value2))
				{
					writer.WriteValue(value2);
				}
				else
				{
					writer.WriteValue(@interface.Object_0);
				}
			}
			else
			{
				writer.WriteNull();
			}
			writer.WriteEndObject();
		}

		private static void smethod_0(JsonReader jsonReader_0, string string_1)
		{
			smethod_1(jsonReader_0);
			if (jsonReader_0.JsonToken_0 != JsonToken.PropertyName || jsonReader_0.Object_0.ToString() != string_1)
			{
				throw new JsonSerializationException("Expected JSON property '{0}'.".smethod_0(CultureInfo.InvariantCulture, string_1));
			}
		}

		private static void smethod_1(JsonReader jsonReader_0)
		{
			if (!jsonReader_0.Read())
			{
				throw new JsonSerializationException("Unexpected end.");
			}
		}

		public override object ReadJson(JsonReader reader, Type objectType, object existingValue, JsonSerializer serializer)
		{
			Interface9 @interface = Class164.smethod_5<Interface9>(Activator.CreateInstance(objectType));
			smethod_0(reader, "Key");
			smethod_1(reader);
			@interface.String_0 = reader.Object_0.ToString();
			smethod_0(reader, "Type");
			smethod_1(reader);
			string typeName = reader.Object_0.ToString();
			Type type = Type.GetType(typeName);
			smethod_0(reader, "Value");
			smethod_1(reader);
			@interface.Object_0 = serializer.Deserialize(reader, type);
			smethod_1(reader);
			return Class164.smethod_3(@interface);
		}

		public override bool CanConvert(Type objectType)
		{
			return objectType.smethod_14("System.Data.EntityKeyMember");
		}
	}
}
